package com.esender.strategy.filter.impl;

import com.esender.common.constant.CacheConstant;
import com.esender.common.enums.ExceptionEnums;
import com.esender.common.exception.StrategyException;
import com.esender.common.model.StandardSubmit;
import com.esender.strategy.client.BeaconCacheClient;
import com.esender.strategy.filter.StrategyFilter;
import com.esender.strategy.util.ErrorSendMsgUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service(value = "blackGlobal")
@Slf4j
public class BlackGlobalStrategyFilter implements StrategyFilter {
    @Autowired
    private BeaconCacheClient beaconCacheClient;
    @Autowired
    private ErrorSendMsgUtil errorSendMsgUtil;
    private static final String TRUE = "1";
    @Override
    public void strategy(StandardSubmit standardSubmit) {
        log.info("【策略模块-全局黑名单校验】   校验ing…………");
        String value = beaconCacheClient.get(CacheConstant.BLACK + standardSubmit.getMobile());
        if (TRUE.equals(value)){
            log.info("【策略模块-全局黑名单校验】 当前手机号是黑名单！mobile:{}",standardSubmit.getMobile());
            standardSubmit.setErrorMsg(ExceptionEnums.BLACK_GLOBAL.getMsg() + "mobile = " + standardSubmit.getMobile());
            errorSendMsgUtil.sendWriteLog(standardSubmit);

            // 推送报告
            errorSendMsgUtil.sendPushReport(standardSubmit);
            throw new StrategyException(ExceptionEnums.BLACK_GLOBAL);
        }
        //4、不是1，正常结束
        log.info("【策略模块-全局级别黑名单校验】   当前手机号不是黑名单！");
    }
}
